package avicit.im.lantop.employeeshortcutkeys.rest;


import avicit.cbb.businessclass.fondsmanage.rest.CbbFondsDbServiceRest;
import avicit.im.common.CommonTreeNode;
import avicit.im.lantop.employeeshortcutkeys.domain.EmployeeShortcutKeys;
import avicit.im.lantop.employeeshortcutkeys.service.EmployeeshortcutService;
import avicit.im.lantop.employeeshortcutkeys.service.api.EmployeeshortcutServiceApi;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@Api(tags = "EmployeeshortcutServiceRest", description = "EmployeeshortcutServiceRest")
@RequestMapping("/api/avicit/im/lantop/employeeshortcutkeys/rest/EmployeeshortcutServiceRest")
public class EmployeeshortcutServiceRest {


    private static final Logger LOGGER = LoggerFactory.getLogger(EmployeeshortcutServiceRest.class);



    @Autowired
    private EmployeeshortcutService employeeshortcutService;


    /**
     * 获得所有首页快捷键数据
     * @param map
     * @return
     */
    @PostMapping("/getEmpItem")
    @ApiOperation(value = "获得所有首页快捷键数据")
    public ResponseMsg<List<Map<String, Object>>> getEmpItem(@ApiParam(value = "获得所有首页快捷键数据", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<List<Map<String, Object>>> responseMsg = new ResponseMsg<>();
        try {
            List<Map<String, Object>> empItem = employeeshortcutService.getEmpItem();
            responseMsg.setResponseBody(empItem);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    /**
     * 根据Id获取对应的快捷键数据
     * @param map
     * @return
     */
    @PostMapping("/getEmpItemById")
    @ApiOperation(value = "根据Id获取对应的快捷键数据")
    public ResponseMsg<EmployeeShortcutKeys> getEmpItemById(@ApiParam(value = "根据Id获取对应的快捷键数据", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg<EmployeeShortcutKeys> responseMsg = new ResponseMsg<>();
        try {
            String id = (String) map.get("id");
            EmployeeShortcutKeys empItemById = employeeshortcutService.getEmpItemById(id);
            responseMsg.setResponseBody(empItemById);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


    @PostMapping("/updateEmpItemById")
    @ApiOperation(value = "根据Id获取对应的快捷键数据")
    public ResponseMsg updateEmpItemById(@ApiParam(value = "根据Id获取对应的快捷键数据", name = "filebasicmanagerservice") @RequestBody Map<String, Object> map) {
        ResponseMsg responseMsg = new ResponseMsg<>();
        try {
            EmployeeShortcutKeys em = (EmployeeShortcutKeys) map.get("em");
            employeeshortcutService.updateEmpItemById(em);
            responseMsg.setRetCode("200");
        } catch (Exception e) {
            responseMsg.setRetCode("201");
            responseMsg.setErrorDesc(e.getMessage());
            e.printStackTrace();
        }
        return responseMsg;
    }


}
